package com.yty.newconsult.controller;

import com.yty.newconsult.entity.DailyNews;
import com.yty.newconsult.service.DailyNewsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (DailyNews)表控制层
 *
 * @author makejava
 * @since 2025-04-11 10:34:23
 */
@RestController
@RequestMapping("dailyNews")
public class DailyNewsController {
    /**
     * 服务对象
     */
    @Resource
    private DailyNewsService dailyNewsService;

    /**
     * 分页查询
     *
     * @param dailyNews 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<DailyNews>> queryByPage(DailyNews dailyNews, PageRequest pageRequest) {
        return ResponseEntity.ok(this.dailyNewsService.queryByPage(dailyNews, pageRequest));
    }


    /**
     * 新增数据
     *
     * @param dailyNews 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<DailyNews> add(DailyNews dailyNews) {
        return ResponseEntity.ok(this.dailyNewsService.insert(dailyNews));
    }




    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.dailyNewsService.deleteById(id));
    }

}

